<?php

namespace App\Filament\Resources\Card\AppResource\Pages;

use App\Filament\Resources\Card\AppResource;
use Filament\Pages\Actions;
use Filament\Resources\Pages\ListRecords;
use Filament\Tables\Actions\DeleteBulkAction;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Collection;

class ListApps extends ListRecords
{
    protected static string $resource = AppResource::class;

    protected function getActions(): array
    {
        return [
            Actions\CreateAction::make(),
        ];
    }

    protected function getTableBulkActions(): array
    {
        return [
            DeleteBulkAction::make()
                ->before(function (Collection $records) {
                    $records->each(function ($item) {
                        $item->cardCodes()->delete();
                        $item->activations()->delete();
                    });
                }),
        ]; // TODO: Change the autogenerated stub
    }

    protected function getTableQuery(): Builder
    {
        return parent::getTableQuery()->where('user_id', auth()->id());
    }
}
